package com.yuncheng.util;

import com.yuncheng.common.base.entity.CcBaseEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description: 云层excel导入导出工具类的拓展修改
 * @date: 2022/10/22
 * @author: xiedong
 */
public class MyExcelUtil {

    /**
     * excel导出通用方法，适用于没有特殊计算的excel导入,修改其支持CcBaseEntity
     */
    public static <T> List<T> exportExcel(List<? extends CcBaseEntity> pageList, String selections) {
        //如果是页面选择记录，则导出当前选中的记录，否则导出满足查询条件的全部记录
        List exportList = pageList;
        if (!StringUtils.isEmpty(selections)) {
            List<String> selectedList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectedList.contains(item.getId())).collect(Collectors.toList());
        }
        return exportList;
    }

}
